import http from "../request";
const apibase = "/api/JobRecordApproval";
import qs from "qs";

//查询所有未删除的审批流
var getApprovalProcessList = function (data) {
  return new Promise((resolve, reject) => {
    http
      .post(apibase + `/GetApprovalProcessList`, data)
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};
//添加审批流
var insApprovalProcess = function (data) {
  return new Promise((resolve, reject) => {
    http
      .post(apibase + `/InsApprovalProcess`, data)
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};
//删除审批流
var delApprovalProcess = function (data) {
  return new Promise((resolve, reject) => {
    http
      .post(apibase + `/DelApprovalProcess`, data)
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};
//修改审批流
var updApprovalProcess = function (data) {
  return new Promise((resolve, reject) => {
    http
      .post(apibase + `/UpdApprovalProcess`, data)
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};

//查询下级信息列表
var getApprovalLevelList = function (data) {
  return new Promise((resolve, reject) => {
    http
      .post(apibase + `/GetApprovalLevelList`, data)
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};
//添加层级
var insApprovalLevel = function (data) {
  return new Promise((resolve, reject) => {
    http
      .post(apibase + `/InsApprovalLevel`, data)
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};
//删除审批层级
var delApprovalLevel = function (data) {
  return new Promise((resolve, reject) => {
    http
      .post(apibase + `/DelApprovalLevel`, data)
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};
//查询审批下级明细列表
var getApprovalProcessRelationList = function (data) {
  return new Promise((resolve, reject) => {
    http
      .post(apibase + `/GetApprovalProcessRelationList`, data)
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};
//新增审批流明细
var insApprovalProcessRelation = function (data) {
  return new Promise((resolve, reject) => {
    http
      .post(apibase + `/InsApprovalProcessRelation`, data)
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};

//删除审批流明细
var delApprovalProcessRelation = function (data) {
  return new Promise((resolve, reject) => {
    http
      .post(apibase + `/DelApprovalProcessRelation`, data)
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};
//查询人员需要审批列表
var getJobRecordList = function (data) {
  const datas = qs.stringify(data);
  return new Promise((resolve, reject) => {
    http
      .post(apibase + `/GetJobRecordList?${datas}`)
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};

export {
  getApprovalProcessList,
  insApprovalProcess,
  delApprovalProcess,
  updApprovalProcess,
  getApprovalLevelList,
  insApprovalLevel,
  delApprovalLevel,
  getApprovalProcessRelationList,
  insApprovalProcessRelation,
  delApprovalProcessRelation,
  getJobRecordList,
};
